from django.shortcuts import render
from django.http import HttpResponse
import logging
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import simplejson
import json

# Create your views here.
@csrf_exempt
def index(request):
    logger = logging.getLogger(__name__)
    logger.debug('index test debug log...')
    logger.info('index test info log...')
    logger.warning('index test warning log...')
    logger.error('index test error log...')
    # return HttpResponse("Hello Django")
    print("receive a request...")
    print("ooooooooooooo")
    mystr = "hhhhhhh"
    print(mystr)
    return JsonResponse({"result":0,"msg":"执行成功"},json_dumps_params={'ensure_ascii':False})

def test(request):
    return render(request,'push.html')

def getbak(request):
    dict = {}
    info = 'Data log save success'
    try:
        if request.method == 'POST':
            # 转换为dict字典数据类型
            req = simplejson.loads(request.raw_post_data)
            print(req)
            username = req['username']
            password = req['password']
            datas = req['datas']
            game_id1 = datas[0]['game_id']
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])

    dict['message']=info
    dict['status'] = 0
    json=simplejson.dumps(dict)
    # return HttpResponse(json)
    return JsonResponse(dict)


def get(request):
    dict = {}
    info = 'Data log save success'
    print(request.GET)
    print(request.method)
    print(request.POST)
    print(request.content_params)
    try:
        if request.method == 'POST':
            # 转换为dict字典数据类型
            name = request.POST.get("name")
            print(name)
            json_str = json.loads(request.body.decode())
            print(json_str)
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])

    dict['message']=info
    dict['status'] = 0
    json=simplejson.dumps(dict)
    # return HttpResponse(json)
    return JsonResponse(dict)